//
//  main.c
//  factorial
//
//  Created by edz on 2020/6/20.
//  Copyright © 2020 edz. All rights reserved.
//

#include <stdio.h>

#if 0
int factorial(int n);

int main(){
    int n;
    scanf("%d",&n);
    if (n < 0) {
        printf("负数没有阶乘\n");
    }
    else if(n >= 0){
        for (int i = 0; i <= n; i++) {
            printf("%d! = %d\n",i,factorial(i));
        }
    }
    return 0;
}

int factorial(int n)
{
    int i;
    int fact = 1;
    for (i = 1; i <= n; i++) {
        fact = fact * i;
    }
    return fact;
}
#endif

#if 0
// 阶乘表
int main(int argc, const char * argv[]) {
    int i,factorial = 1;
    for (i = 1; i <= 10; i++) {
        factorial = factorial * i;
        printf("%d! = %d\n",i,factorial);
    }
    return 0;
}
#endif

#if 0
// 优化阶乘表
int main(){
    int factorial=1,n;
    int i = 1;
    scanf("%d",&n);
    printf("0! = 1\n");
    while (i <= n) {
        factorial = factorial * i;
        printf("%d! = %d\n",i,factorial);
        i++;
    }
    return 0;
}
#endif
